package com.springboot.erp.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.springboot.erp.entity.JshSupplier;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Options;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

@Mapper
public interface JshSupplierMapper extends BaseMapper<JshSupplier> {

    Page<JshSupplier> selectForPagesSup(@Param("supplier") String supplier, @Param("phoneNum") String phoneNum,
                                     @Param("telephone") String telephone,
                                     Page<JshSupplier> page);
@Select("INSERT INTO jsh_supplier (type, supplier, telephone, email, begin_need_pay, tax_num, bank_name, address, description, contacts, phone_num, fax, all_need_pay, tax_rate, account_number, sort, delete_flag, enabled, advance_in) VALUES ('供应商', #{supplier},   #{telephone}, #{email}, #{beginNeedPay},  #{taxNum}, #{bankName}, #{address},  #{description},  #{contacts},  #{phoneNum},  #{fax},  #{allNeedPay},  #{taxRate},   #{accountNumber},  #{sort}, #{deleteFlag}, #{enabled},  #{advanceIn}  )")
@Options(useGeneratedKeys = true, keyProperty = "id")
    void insrtONeSup(JshSupplier jshSupplier);

@Select("UPDATE jsh_supplier SET supplier = #{supplier}, telephone = #{telephone}, email = #{email}, begin_need_pay = " +
        "#{beginNeedPay}, tax_num = #{taxNum}, bank_name = #{bankName}, address = #{address}, description = #{description}, contacts = #{contacts}," +
        " phone_num = #{phoneNum}, fax = #{fax}, all_need_pay = #{allNeedPay}, tax_rate = #{taxRate}, account_number = #{accountNumber}, sort = #{sort}," +
        " delete_flag = #{deleteFlag}, enabled = #{enabled}, advance_in = #{advanceIn} WHERE id = #{id} and type = '供应商'")
void updateOneSup(JshSupplier jshSupplier);
@Select("DELETE FROM jsh_supplier WHERE id = #{id} and delete_flag = 0 and type = '供应商' ")
void deleteOneSup(@Param("id") Integer id);


Page<JshSupplier> selectForPagesSupC(@Param("supplier") String supplier, @Param("phoneNum") String phoneNum,
                                        @Param("telephone") String telephone,
                                        Page<JshSupplier> page);

    @Select("INSERT INTO jsh_supplier (type, supplier, telephone, email, begin_need_pay, tax_num, bank_name, address, description, contacts, phone_num, fax, all_need_pay, tax_rate, account_number, sort, delete_flag, enabled, advance_in) VALUES ('客户', #{supplier},   #{telephone}, #{email}, #{beginNeedPay},  #{taxNum}, #{bankName}, #{address},  #{description},  #{contacts},  #{phoneNum},  #{fax},  #{allNeedPay},  #{taxRate},   #{accountNumber},  #{sort}, #{deleteFlag}, #{enabled},  #{advanceIn}  )")
    @Options(useGeneratedKeys = true, keyProperty = "id")
    void insrtONeSupC(JshSupplier jshSupplier);

    @Select("UPDATE jsh_supplier SET supplier = #{supplier}, telephone = #{telephone}, email = #{email}, begin_need_pay = " +
            "#{beginNeedPay}, tax_num = #{taxNum}, bank_name = #{bankName}, address = #{address}, description = #{description}, contacts = #{contacts}," +
            " phone_num = #{phoneNum}, fax = #{fax}, all_need_pay = #{allNeedPay}, tax_rate = #{taxRate}, account_number = #{accountNumber}, sort = #{sort}," +
            " delete_flag = #{deleteFlag}, enabled = #{enabled}, advance_in = #{advanceIn} WHERE id = #{id} and type = '客户'")
    void updateOneSupC(JshSupplier jshSupplier);

    @Select("DELETE FROM jsh_supplier WHERE id = #{id} and delete_flag = 0 and type = '客户' ")
    void deleteOneSupC(@Param("id") Integer id);
}
